<?
$uidstring = $_GET['users'];
$uidlist = explode(",", rtrim($uidstring, ','));

foreach ($uidlist as $uid) {
	$sr=ldap_search($conn, $GLOBALS["dc"], "(&(objectClass=person)(uidnumber=$uid))");
	$userlist[] = ldap_get_entries($conn, $sr);
}

echo "<table class=framed>";
echo "<tr><td colspan=2 class=tbhead>Valda användare</td></tr><tr><td>";
$sw = 0;
foreach ($userlist as $info) {
	if ($sw) echo ", ";
	echo $info[0]["cn"][0];
	$sw = 1;
}
echo '</td></tr>';
echo '<input type="hidden" name="users" value="'.$uidstring.'">';

echo '<tr><td>&nbsp;</td></tr>';

echo '<tr><td class="tbhead" colspan="2">med dessa användare..</td></tr>';
$sr=ldap_search($conn, $GLOBALS["dc"], "(objectclass=posixGroup)");
$groups = ldap_get_entries($conn, $sr);
unset( $groups['count'] );

echo "<tr><td>Lägg till befintlig grupp:</td><td>\n";
echo "<select name=\"addToGroup\">\n";
echo "<option value=\"\">\n";
foreach ($groups as $i) {
	if ($i["gidnumber"][0] != 515 && $i["gidnumber"][0] != 513) {
		echo "<option value=\",".$i["cn"][0]."\">".$i["cn"][0]."\n";
        }
}
echo "</select></td></tr>\n";

echo "<tr><td>Lägg till i ny grupp</td><td><input type=\"text\" name=\"addToNewGroup\"></td></tr>\n";

echo "<tr><td>Ta bort ur grupp:</td><td>\n";
echo "<select name=\"deleteFromGroup\">\n";
echo "<option value=\"\">\n";
foreach ($groups as $i) {
	if ($i["gidnumber"][0] != 515 && $i["gidnumber"][0] != 513) {
		echo "<option value=\",".$i["cn"][0]."\">".$i["cn"][0]."\n";
        }
}
echo "</select></td></tr>\n";

echo "<input type=hidden value=\"TRUE\" name=\"b_modmany\">";
echo '</table>';
?>
